home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / us20src.zip / DMERGE.C < prev    next >
C/C++ Source or Header  |  1992-06-26  |  6KB  |  283 lines

  1. /*    DMERGE:    Dictionary Merge Utility for MicroSPELL 2.0
  2.         Spell Checker and Corrector
  3.  
  4.         (C)opyright May 1990 by Daniel Lawrence
  5.         All Rights Reserved
  6.  
  7.     Revision History:
  8.  
  9. */
  10.  
  11. #define    maindef    1
  12.  
  13. #include    <stdio.h>
  14. #include    "dopt.h"
  15. #include    "dstruct.h"
  16. #include    "ddef.h"
  17.  
  18. /*    GLOBALS for DMERGE    */
  19.  
  20. char dname[NSTRING];        /* main output dictionary text file */
  21. int upflag;            /* processing upper case flag */
  22.  
  23. main(argc, argv)
  24.  
  25. int argc;    /* command line argument count */
  26. char **argv;    /*              argument vector */
  27.  
  28. {
  29.     WORD *tword;
  30.  
  31.     /* check to see if they need help.... */
  32.     if (argc < 3) {
  33.         usage();
  34.         exit(EXBADOPT);
  35.     }
  36.  
  37.     /* announce us */
  38.     printf("DMERGE %s    Dictionary merge Utility\n", VERSION);
  39.  
  40.     /* grab the output dictionary name */
  41.     --argc;
  42.     argv++;
  43.     strcpy(dname, argv[0]);
  44.  
  45.     /* init the lcase array */
  46.     init_lcase();
  47.  
  48.     /* and read in the user word lists */
  49.     while (--argc) {
  50.         argv++;        /* skip to next argument */
  51.         uread(argv[0]);    /* and read the dictionary in */
  52.     }
  53.  
  54.     /* sort the common word list */
  55.     comsort();
  56.     if (numfiltr)
  57.         printf("%u User words loaded\n", numfiltr);
  58.     else {
  59.         printf("%%No user words loaded\n");
  60.         exit(EXBADOPT);
  61.     }
  62.  
  63.     if (mopen() == FALSE)
  64.         exit(EXMDICT);
  65.  
  66.     /* open the output dictionary file */
  67.     if ((outfile = fopen(dname, "w")) == NULL) {
  68.         printf("%%Can not open output dictionary file\n");
  69.         exit(EXTEMP);
  70.     }
  71.  
  72.     /* and do the merge */
  73.     printf("[Merging....]");
  74.     merge();
  75.     printf("\n%u words merged ... new dictionary is %u words long\n",
  76.             numfiltr, totwords);
  77.  
  78.     mclose();
  79.     fclose(outfile);
  80.     exit(EXGOOD);
  81. }
  82.  
  83. usage()        /* print the command line usage */
  84.  
  85. {
  86.     printf("DMERGE:    Dictionary Merge Utility\n");
  87.     printf("    for MicroSPELL %s\n",VERSION);
  88.     puts("\nUsage\n");
  89.     puts("    dmerge <output dictionary> <user file> {<user file>..}\n");
  90. }
  91.  
  92. int merge()        /* do a merge run against the main dictionary    */
  93.  
  94. {
  95.     register char **curword;/* ptr to current word */
  96.     register int cmp;    /* result of comparison */
  97.     char mword[NSTRING];    /* current dictionary word */
  98.  
  99.     /* make sure the common word list ends with hivalue */
  100.     strcpy(cword[numfiltr], hivalue);
  101.     upflag = TRUE;
  102.  
  103.     /* start with the first word in each list */
  104.     strcpy(mword, nxtmword());
  105.     curword = &cword[0];
  106.  
  107.     while (strcmp(*curword, hivalue) < 0 || strcmp(mword, hivalue) < 0) {
  108.  
  109.         /* compare a dictionary word and a user word */
  110.         cmp = strcmp(*curword, mword);
  111.  
  112.         /* and write out the appropriate one */
  113.         if (cmp > 0) {
  114.             outword(mword);
  115.             strcpy(mword, nxtmword());
  116.         } else if (cmp < 0) {
  117.             outword(*curword);
  118.             curword++;
  119.         } else {
  120.             outword(*curword);
  121.             strcpy(mword, nxtmword());
  122.             curword++;
  123.         }
  124.     }
  125. }
  126.  
  127. outword(word)    /* output a word to the new main dictionary text file */
  128.  
  129. char *word;    /* word to write to dictionary */
  130.  
  131. {
  132.     /* if this is the seperator character, toggle uppercase flag off */
  133.     if (*word == SEPCHAR)
  134.         upflag = FALSE;
  135.  
  136.     /* If we switch from upper to lower case with no seperator,
  137.        insert one */
  138.     if (upflag)
  139.         if (islower(*word)) {
  140.             fprintf(outfile, "%c\n", SEPCHAR);
  141.             upflag = FALSE;
  142.         }
  143.  
  144.     /* and finally, dump the word out */
  145.     fprintf(outfile, "%s\n", word);
  146.     totwords++;
  147. }
  148.  
  149. #if    RAMSIZE & LATTICE & MSDOS
  150. /*    These routines will allow me to track memory usage by placing
  151.     a layer on top of the standard system malloc() and free() calls.
  152.     with this code defined, the number of allocated bytes is displayed
  153.     in the upper right corner of the screen
  154. */
  155.  
  156. #undef    malloc
  157. #undef    free
  158.  
  159. char *allocate(nbytes)    /* allocate nbytes and track */
  160.  
  161. unsigned nbytes;    /* # of bytes to allocate */
  162.  
  163. {
  164.     char *mp;    /* ptr returned from malloc */
  165.     char *malloc();
  166.  
  167.     mp = malloc(nbytes);
  168.     if (mp) {
  169.         envram += nbytes;
  170. #if    RAMSHOW
  171.         dspram();
  172. #endif
  173.     }
  174.  
  175.     return(mp);
  176. }
  177.  
  178. release(mp)    /* release malloced memory and track */
  179.  
  180. char *mp;    /* chunk of RAM to release */
  181.  
  182. {
  183.     unsigned *lp;    /* ptr to the long containing the block size */
  184.  
  185.     if (mp) {
  186.         lp = ((unsigned *)mp) - 1;
  187.  
  188.         /* update amount of ram currently malloced */
  189.         envram -= (long)*lp - 2;
  190.         free(mp);
  191. #if    RAMSHOW
  192.         dspram();
  193. #endif
  194.     }
  195. }
  196.  
  197. #if    RAMSHOW
  198. dspram()    /* display the amount of RAM currently malloced */
  199.  
  200. {
  201.     char mbuf[20];
  202.     char *sp;
  203.  
  204. /*    TTmove(term.t_nrow - 1, 70);*/
  205.     sprintf(mbuf, "[%lu]", envram);
  206.     sp = &mbuf[0];
  207.     puts(sp);
  208. }
  209. #endif
  210. #endif
  211.  
  212. #if    AZTEC & MSDOS
  213. #undef    fgetc
  214. /*    a1getc:        Get an ascii char from the file input stream
  215.             but DO NOT strip the high bit
  216. */
  217.  
  218. int a1getc(fp)
  219.  
  220. FILE *fp;
  221.  
  222. {
  223.     int c;        /* translated character */
  224.  
  225.     c = getc(fp);    /* get the character */
  226.  
  227.     /* if its a <LF> char, throw it out  */
  228.     while (c == 10)
  229.         c = getc(fp);
  230.  
  231.     /* if its a <RETURN> char, change it to a LF */
  232.     if (c == '\r')
  233.         c = '\n';
  234.  
  235.     /* if its a ^Z, its an EOF */
  236.     if (c == 26)
  237.         c = EOF;
  238.  
  239.     return(c);
  240. }
  241. #endif
  242.  
  243. perform(cmd)    /* send out a DOS command and execute it */
  244.  
  245. char *cmd;    /* command to execute */
  246.  
  247. {
  248.     if (swdebug)    /* output command string with diagnostics */
  249.         puts(cmd);
  250.  
  251. #if    LATTICE & ~CMS
  252.     forkl(getenv("COMSPEC"),"command","-C",cmd,NULL);
  253.     return(wait());
  254. #endif
  255.  
  256. #if    (AZTEC & ~AMIGA) | CMS
  257.     system(cmd);
  258.     return(TRUE);
  259. #endif
  260.  
  261. #if    AZTEC & AMIGA
  262.     fexecl(cmd, NULL);
  263.     return(wait());
  264. #endif
  265. }
  266.  
  267. #if    CMS
  268. #undef    fopen
  269. /*    The IBM 30xx likes to tell us when file opens
  270.     fail...it's too chatty....I like to handle these myself    */
  271.  
  272. FILE *cmsopen(file, mode)
  273.  
  274. char *file;    /* name of file to open */
  275. char *mode;    /* mode to open it in */
  276.  
  277. {
  278.     quiet(1);
  279.     return(fopen(file,mode));
  280. }
  281. #endif
  282.  
  283.